package guowei.guliproduct.product.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;

import guowei.guliproduct.product.entity.CategoryEntity;
import guowei.guliproduct.product.service.CategoryService;
import guowei.guliproduct.product.vo.BrandsRelationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import guowei.guliproduct.product.entity.CategoryBrandRelationEntity;
import guowei.guliproduct.product.service.CategoryBrandRelationService;
import guowei.common.utils.PageUtils;
import guowei.common.utils.R;



/**
 * 品牌分类关联
 *
 * @author guoguo
 * @email 1573746397@qq.com
 * @date 2023-05-21 17:38:07
 */
@RestController
@RequestMapping("product/categorybrandrelation")
public class CategoryBrandRelationController {
    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;


    /**
     * 发布商品时，查询到的品牌分类信息
     * @param catId
     * @return
     */
    @GetMapping("/brands/list")
    public R getBrandsRelation(@RequestParam Long catId){
        ArrayList<BrandsRelationVo> brands = categoryBrandRelationService.selectallRelations(catId);
        return R.ok().put("data",brands);
    }

    /**
     * 列表
     */
    @RequestMapping("/catelog/list")
    //@RequiresPermissions("product:categorybrandrelation:list")
    public R list(@RequestParam Map<String, Object> params){

//        PageUtils page = categoryBrandRelationService.queryPage(params);

        PageUtils page = categoryBrandRelationService.queryPagrByBrandId(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:categorybrandrelation:info")
    public R info(@PathVariable("id") Long id){
		CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);

        return R.ok().put("categoryBrandRelation", categoryBrandRelation);
    }

    /**
     * 根据前端传来的catlog_id和brand_id得到brandname和catelogname进行保存信息
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:categorybrandrelation:save")
    public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){

        categoryBrandRelationService.saveCateLogIdBrandId(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:categorybrandrelation:update")
    public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.updateById(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:categorybrandrelation:delete")
    public R delete(@RequestBody Long[] ids){
		categoryBrandRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
